import java.util.*;
public class BiteDay41 {
    private static int check(char[][] arr, char ch){
        for(int i = 0; i < 20; i++){
            for(int j = 0; j < 20; j++){
                if(arr[i][j] == ch){
                    //上
                    if(i - 4 >= 0 && i - 4 < 20){
                        if(arr[i-4][j]==arr[i-3][j]
                                &&arr[i-3][j]==arr[i-2][j]
                                &&arr[i-2][j]==arr[i-1][j]
                                &&arr[i-1][j]==arr[i][j]){
                            return 1;
                        }
                    }
                    //下
                    if(i+4>=0&&i+4<20){
                        if(arr[i][j]==arr[i+1][j]
                        && arr[i+1][j]==arr[i+2][j]
                        && arr[i+2][j]==arr[i+3][j]
                        && arr[i+3][j]==arr[i+4][j]){
                            return 1;
                        }
                    }
                    //左
                    if(j-4>=0&&j-4<20){
                        if(arr[i][j]==arr[i][j-1]
                        && arr[i][j-1]==arr[i][j-2]
                        && arr[i][j-2]==arr[i][j-3]
                        && arr[i][j-3]==arr[i][j-4]){
                            return 1;
                        }
                    }
                    //右
                    if(j+4>=0&&j+4<20){
                        if(arr[i][j]==arr[i][j+1]
                        && arr[i][j+1]==arr[i][j+2]
                        && arr[i][j+2]==arr[i][j+3]
                        && arr[i][j+3]==arr[i][j+4]){
                            return 1;
                        }
                    }
                    //左对角线
                    if(i+4>=0&&i+4<20
                    && j+4>=0&&j+4<20){
                        if(arr[i][j]==arr[i+1][j+1]
                        && arr[i+1][j+1]==arr[i+2][j+2]
                        && arr[i+2][j+2]==arr[i+3][j+3]
                        && arr[i+3][j+3]==arr[i+4][j+4]){
                            return 1;
                        }
                    }
                    //右对角线
                    if(i+4>=0&&i+4<20
                            && j-4>=0&&j-4<20){
                        if(arr[i][j]==arr[i+1][j-1]
                                && arr[i+1][j-1]==arr[i+2][j-2]
                                && arr[i+2][j-2]==arr[i+3][j-3]
                                && arr[i+3][j-3]==arr[i+4][j-4]){
                            return 1;
                        }
                    }
                }
            }
        }
        return 0;
    }
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            char[][] arr = new char[20][20];
            int i = 0;
            for(i = 0; i < 20; i++){
                String s = sc.next();
                arr[i] = s.toCharArray();
            }
            int ret = 0;
            ret = check(arr, '+') + check(arr, '*');
            if(ret != 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int n = sc.nextInt();
            Stack<Integer> stack = new Stack<>();
            for(int i = 0; i < n; i++){
                String s = sc.next();
                if(s.charAt(0) == '+'){
                    int num1 = stack.pop();
                    int num2 = stack.pop();
                    stack.push(num1+num2);
                } else if (s.charAt(0) == '-') {
                    int num1 = stack.pop();
                    int num2 = stack.pop();
                    stack.push(num1-num2);
                }else if (s.charAt(0) == '*') {
                    int num1 = stack.pop();
                    int num2 = stack.pop();
                    stack.push(num1*num2);
                }else if (s.charAt(0) == '/') {
                    int num1 = stack.pop();
                    int num2 = stack.pop();
                    stack.push(num1/num2);
                }else{
                    stack.push(Integer.parseInt(s));
                }
            }
            System.out.println(stack.peek());
        }
    }
}
